/**
 * 
 */
package com.nh.action;

import java.sql.Timestamp;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.nh.entity.NgExpertInterlocution;
import com.nh.entity.NgExpertRepay;

/**
 * 项目名称：NotoginsengManage
 * 
 * 类名称：ExpertInterlocutionAction
 * 
 * 类描述：
 * 
 * 创建人：李兴建
 * 
 * E-mail:lxj08193@163.com
 * 
 * 创建时间：2012-11-11 下午07:53:24
 * 
 * 修改人：李兴建
 * 
 * 修改时间：2012-11-11 下午07:53:24
 * 
 * 修改备注：
 * 
 * @version
 */
public class ExpertInterlocutionAction extends BaseAction {
	private Long optionId;
	private NgExpertInterlocution expertInterlocution;
	private Long recoveryId;
	private String content;

	/**
	 * 未回复列表页面
	 * 
	 * @return
	 */
	public String questionListPage() {
		Criteria criteria = this.createCriteria(NgExpertInterlocution.class);
		criteria.add(Restrictions.eq("state", 0));
		criteria.addOrder(Order.desc("questionTime"));
		this.queryByPage(criteria, "expertInterlocutionAction!questionListPage.action", 10);

		this.setTitle("未回复列表");
		return "questionListPage";
	}

	/**
	 * 已回复咨询列表页面
	 * 
	 * @return
	 */
	public String answerListPage() {
		Criteria criteria = this.createCriteria(NgExpertInterlocution.class);
		criteria.add(Restrictions.eq("state", 1));
		criteria.addOrder(Order.desc("answerTime"));
		this.queryByPage(criteria, "expertInterlocutionAction!answerListPage.action", 10);
		this.setTitle("已回复列表");
		return "questionListPage";
	}
	/**
	 * 回复列表
	 * 
	 * @return
	 */
	public String expertRecoveryList() {
		expertInterlocution = this.getBaseService().findById(optionId, NgExpertInterlocution.class);
		Criteria criteria = this.createCriteria(NgExpertRepay.class);
		criteria.addOrder(Order.desc("recoverTime"));
		criteria.add(Restrictions.eq("recoveryId", expertInterlocution.getId()));
		this.queryByPage(criteria, "expertInterlocutionAction!expertRecoveryList.action", 10);
		this.setTitle("咨询回复列表");
		return "expertRecoveryList";
	}
	/**
	 * 删除
	 * 
	 * @return
	 */
	public String removeExpertInterlocution() {
		this.getBaseService().delete(optionId, NgExpertInterlocution.class);
		return answerListPage();
	}

	/**
	 * 回复页面
	 * 
	 * @return
	 */
	public String replyPage() {
		expertInterlocution = this.getBaseService().findById(optionId, NgExpertInterlocution.class);
		this.setTitle("回复问题");
		return "replyPage";
	}

	/**
	 * 保存回复
	 * 
	 * @return
	 */
	public String replySave() {
		expertInterlocution.setAnswerTime(new Timestamp(System.currentTimeMillis()));
		expertInterlocution.setAdminId(this.getCurrentAdmin().getId());
		expertInterlocution.setAdminDiscription(this.getCurrentAdmin().getRealEname()+"回复");
		expertInterlocution.setState(1);
		/*
		NgExpertInterlocution temp=this.getBaseService().findById(expertInterlocution.getId(), NgExpertInterlocution.class);
		String conten="";
		if(StringUtils.isNotEmpty(temp.getAnswer())){
			conten=temp.getAnswer();
			conten=conten+ "<br/>";
		}
		expertInterlocution.setAnswer(conten+content+"【专家:"+this.getCurrentAdmin().getRealEname()+"回复】");
		*/
		NgExpertRepay expertRepay=new NgExpertRepay();
		expertRepay.setRecoveryId(expertInterlocution.getId());
		expertRepay.setContent(content);
		expertRepay.setRecoverTime(new Timestamp(System.currentTimeMillis()));
		expertRepay.setRecoveryType(this.getCurrentAdmin().getAdminType()+1);
		expertRepay.setUserCode(this.getCurrentAdmin().getId()+"");
		expertRepay.setUserStr(this.getCurrentAdmin().getRealEname());
		this.getBaseService().save(expertRepay);
		
		this.getBaseService().saveOrUpdate(expertInterlocution, NgExpertInterlocution.class);
		return questionListPage();
	}
	
	/**
	 * 删除回复
	 * 
	 * @return
	 */
	public String recoveryRemove() {
		this.getBaseService().delete(recoveryId, NgExpertRepay.class);
		return expertRecoveryList();
	}
	/**
	 * @return the optionId
	 */
	public Long getOptionId() {
		return optionId;
	}

	/**
	 * @param optionId
	 *            the optionId to set
	 */
	public void setOptionId(Long optionId) {
		this.optionId = optionId;
	}

	/**
	 * @return the recoveryId
	 */
	public Long getRecoveryId() {
		return recoveryId;
	}

	/**
	 * @param recoveryId the recoveryId to set
	 */
	public void setRecoveryId(Long recoveryId) {
		this.recoveryId = recoveryId;
	}

	/**
	 * @return the expertInterlocution
	 */
	public NgExpertInterlocution getExpertInterlocution() {
		return expertInterlocution;
	}

	/**
	 * @param expertInterlocution
	 *            the expertInterlocution to set
	 */
	public void setExpertInterlocution(NgExpertInterlocution expertInterlocution) {
		this.expertInterlocution = expertInterlocution;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}
}
